﻿<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Bezdelnick
 * Date: 12.04.13
 * Time: 15:13
 * To change this template use File | Settings | File Templates.
 */
require_once("Config.php");
require_once("common/Lang.php");
require_once("persistence/SearchFilmCriteria.php");
require_once("dao/FilmDao.php");
require_once("dao/GenreDao.php");

$filmDao = new FilmDao();
$films = $filmDao->load();

$genreDao = new GenreDao();

if (
    isset($_POST['film_name']) ||
    isset($_POST['from_year']) ||
    isset($_POST['to_year']) ||
    isset($_POST['selected_genres']) ||
    isset($_POST['selected_actors']) ||
    isset($_POST['selected_countries'])
) {
    $criteria = new SearchFilmCriteria();

    if (isset($_POST['film_name']))
        $criteria->setName($_POST['film_name']);
    else $criteria->setName("");

    if (isset($_POST['from_year']))
        $criteria->setYearFrom($_POST['from_year']);
    else $criteria->setYearFrom(1900);

    if (isset($_POST['to_year']))
        $criteria->setYearTo($_POST['to_year']);
    else $criteria->setYearTo(2200);

    if (isset($_POST['selected_genres']))
        $criteria->setGenres($_POST['selected_genres']);

    if (isset($_POST['selected_actors']))
        $criteria->setActors($_POST['selected_actors']);

    if (isset($_POST['selected_countries']))
        $criteria->setCountries($_POST['selected_countries']);

    $films = $filmDao->loadByCriteria($criteria);
}
?>

<!-- Content table -->
<h2 class="white-font">Поиск фильмов</h2>
<table class="content-table" border="0">
    <thead style="background-color: #ffd700;">
    <tr>
        <td style="width: 30%;">Название</td>
        <td style="width: 35%;">Описание</td>
        <td style="width: 25%;">Год выпуска</td>
        <td style="width: 25%;">Жанры</td>
    </tr>
    </thead>
    <tbody>
    <? foreach ($films as $film) { ?>
    <tr style="background-color: #efefef;">
        <td><?= $film->getName() ?></td>
        <td><?= $film->getDescription() ?></td>
        <td><?= $film->getYear() ?></td>
        <td>
            <? $genres = $genreDao->loadByFilmId($film->getId()) ?>
            <? foreach ($genres as $item) { ?>
            <?= $item->getName() . " " ?>
            <? } ?>
        </td>
    </tr>
    <? } ?>
    </tbody>
</table>